package com.eedi.framework.oauth2.enums;

import cn.hutool.core.util.ArrayUtil;
import com.eedi.framework.common.enums.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

/**
 * OAuth2 授权类型（模式）的枚举
 *
 * @author 永聚长青源码
 */
@AllArgsConstructor
@Getter
@ToString
public enum OrgOAuth2GrantTypeEnum implements BaseEnum<String,String> {
    // 密码模式
    PASSWORD("password","密码模式"),
    // 授权码模式
    AUTHORIZATION_CODE("authorization_code","授权码模式"),
    // 简化模式
    IMPLICIT("implicit","简化模式"),
    // 客户端模式
    CLIENT_CREDENTIALS("client_credentials","客户端模式"),
    // 刷新模式
    REFRESH_TOKEN("refresh_token","刷新模式"),
    ;

    private final String grantType;
    private final String desc;

    public static OrgOAuth2GrantTypeEnum getByGranType(String grantType) {
        return ArrayUtil.firstMatch(o -> o.getGrantType().equals(grantType), values());
    }

    @Override
    public String getCode() {
        return this.desc;
    }

    @Override
    public String title() {
        return "机构授权类型(模式)";
    }
}
